<?php

	// TITLE: Sweat_equity AUTO MODEL
	// FILE: scaffolding/model/sweat_equity.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createSweatEquity = function($con, $sweatEquity) {
		$sql = 'INSERT INTO sweat_equity (homeowner_id, work_id, when_entered, who_entered, when_authorized, who_authorized) VALUES (';
		$sql .= $sweat_equity->getHomeownerId() . ', ';
		$sql .= $sweat_equity->getWorkId() . ', ';
		$sql .= $sweat_equity->getWhenEntered() . ', ';
		$sql .= $sweat_equity->getWhoEntered() . ', ';
		$sql .= $sweat_equity->getWhenAuthorized() . ', ';
		$sql .= $sweat_equity->getWhoAuthorized() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readSweatEquity = function($con, $id) {
		$sql = 'SELECT * FROM sweat_equity WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$sweatEquity = new SweatEquity();
			$sweatEquity->setHomeownerId($dbio->select($readHomeowner(result[0])));
			$sweatEquity->setWorkId($dbio->select($readWork(result[1])));
			$sweatEquity->setWhenEntered(result[2]);
			$sweatEquity->setWhoEntered(result[3]);
			$sweatEquity->setWhenAuthorized(result[4]);
			$sweatEquity->setWhoAuthorized(result[5]);
		} else {
			$sweatEquity = false;
		}
		return $sweatEquity;
	};

	$updateSweatEquity = function($con, $sweatEquity) {
		$sql = 'UPDATE sweat_equity SET ';
		$sql .= 'homeowner_id = ' . $sweat_equity->getHomeownerId() . ', ';
		$sql .= 'work_id = ' . $sweat_equity->getWorkId() . ', ';
		$sql .= 'when_entered = ' . $sweat_equity->getWhenEntered() . ', ';
		$sql .= 'who_entered = ' . $sweat_equity->getWhoEntered() . ', ';
		$sql .= 'when_authorized = ' . $sweat_equity->getWhenAuthorized() . ', ';
		$sql .= 'who_authorized = ' . $sweat_equity->getWhoAuthorized() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteSweatEquity = function($con, $id) {
		$sql = 'DELETE FROM sweat_equity WHERE homeowner_id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listSweatEquity = function($con) {
		$sql = 'SELECT * FROM sweat_equity';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$sweatEquitys = array();
			while ($result = mysqli_fetch_array($results)) {
				$sweatEquity = new SweatEquity();
				$sweatEquity->setHomeownerId($dbio->select($readHomeowner(result[0])));
				$sweatEquity->setWorkId($dbio->select($readWork(result[1])));
				$sweatEquity->setWhenEntered(result[2]);
				$sweatEquity->setWhoEntered(result[3]);
				$sweatEquity->setWhenAuthorized(result[4]);
				$sweatEquity->setWhoAuthorized(result[5]);
				$sweatEquitys[] = sweatEquity;
			}// end while
		} else {
			$sweatEquitys = false;
		}
		return $sweatEquitys;
	};

